﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Data;
using Maticsoft.DBUtility;

namespace SkWeb.RiskDB
{
    public partial class ImgDisp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string strId = Request.QueryString["id"];
            string strScale = Request.QueryString["scale"];
            string strType  = Request.QueryString["map_type"];
            string strJh = Request.QueryString["jh"];
            if (String.IsNullOrEmpty(strScale))
            {
                strScale = "12";
            }
            if(String.IsNullOrEmpty(strId))
            {
                return;
            }
            string strOverlayer = GetOverlayer(strId,strJh);
            WebClient client = new WebClient();
            string fileName = DateTime.Now.Ticks.ToString() + ".jpg";
            string path = Server.MapPath("~/tempImg/") + fileName;
            string strIcon = "https://chart.googleapis.com/chart?chst=d_bubble_icon_text_small&chld=ski|bb|Wheeee!|FFFFFF|000000";
            client.DownloadFile("http://maps.google.com/maps/api/staticmap?&size=400x380&sensor=false&language=zh-CN&zoom=" + strScale +"&maptype="+strType+ strOverlayer, path);
            this.Image1.ImageUrl = "../tempImg/" + fileName;
        }
        //%257C
        private string  GetOverlayer(string strId,string strJh)
        {
            string strSql = "select name,lng,lat,rank,block_id from tb_wellinfo where id="+strId;
            DataTable dt = DbHelperOra.Query(strSql).Tables[0];
            DataRow dr = dt.Rows[0];
            string str = "&markers=icon:" + "http://chart.apis.google.com/chart?chst=d_bubble_text_small%26chld=bb%257C"+strJh+"%257CFFFF88%257C000000" + "|" + dr["lat"].ToString() + "," + dr["lng"].ToString();// +"&markerStyles=l," + dr["rank"].ToString() + ",0xff0000";
           
            string strBlockId = dr["block_id"].ToString();
            string strRank = dr["rank"].ToString();
            if (!String.IsNullOrEmpty(strBlockId))
            {
                strSql = "select data,type from tb_riskblockinfo where id=" + strBlockId;
                dt = DbHelperOra.Query(strSql).Tables[0];
                dr = dt.Rows[0];

                string strData = dr["data"].ToString();

                string[] temArr = strData.Split(',');//&language=zh-CN&path=weight:3|fillcolor:yellow:
                strData = "&path=weight:3|fillcolor:";
                string strColor = "0xff0000";
                if (strRank == "2")
                {
                    strColor = "0x00ff00";
                }
                else if (strRank == "3")
                {
                    strColor = "0x0000ff";
                }
                strData += strColor+"|";

                Array.Reverse(temArr);
                for (int i = 0; i < temArr.Length; i++)
                {
                    char ch = ',';
                    if (i % 2 == 1)
                    {
                        ch = '|';
                    }
                    strData += temArr[i] + ch;
                }
                strData += temArr[0] + ',' + temArr[1] ;               
                str = str+strData;
            }
            
            return str;
        }
    }
}